package com.minhua.jijiehao2.mainframe.account.addaccountactivity.impl

import android.text.TextUtils
import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.account.addaccountactivity.imp.IAddAccountPresenter
import com.minhua.jijiehao2.mainframe.account.addaccountactivity.imp.IAddAccountView
import com.minhua.jijiehao2.utils.T

class AddAccountPresenter : BaseMvpPresenter<IAddAccountView>(), IAddAccountPresenter {

    private val mAddAccountModel = AddAccountModel()

    override fun addAccount() {
        val pCode = v?.pCode() ?: ""
        val userId = v?.userId() ?: ""
        val userName = v?.userName() ?: ""
        val ordersName = v?.ordersName() ?: ""
        val amtByMonth = v?.amtByMonth() ?: ""
        val repayType = v?.repayType() ?: ""
        val totalPeriods = v?.totalPeriods() ?: ""
        val currentPeriods = v?.currentPeriods() ?: ""
        val repayDay = v?.repayDay() ?: ""
        val repayRemind = v?.repayRemind() ?: ""
        val repayStatus = v?.repayStatus() ?: ""

        if (TextUtils.isEmpty(pCode) ||
                TextUtils.isEmpty(userId) ||
                TextUtils.isEmpty(userName) ||
                TextUtils.isEmpty(ordersName) ||
                TextUtils.isEmpty(amtByMonth) ||
                TextUtils.isEmpty(repayType) ||
                TextUtils.isEmpty(totalPeriods) ||
                TextUtils.isEmpty(currentPeriods) ||
                TextUtils.isEmpty(repayDay) ||
                TextUtils.isEmpty(repayRemind) ||
                TextUtils.isEmpty(repayStatus) ||
                repayRemind.contains("请") ||
                repayDay.contains("请")) {
            T.showShort("请将信息填写完整")
            return
        }

        val map = ParamsMap()
        map.put("pCode", pCode)
        map.put("userId", userId)
        map.put("userName", userName)
        map.put("ordersName", ordersName)
        map.put("amtByMonth", amtByMonth)
        map.put("repayType", repayType)
        map.put("totalPeriods", totalPeriods)
        map.put("currentPeriods", currentPeriods)
        map.put("repayDay", repayDay)
        map.put("repayRemind", repayRemind)
        map.put("repayStatus", repayStatus)

        mAddAccountModel.addAccount(map, object : CallBack<Any>() {
            override fun onSuccess(t: BaseBean<Any>) {
                v?.onAddSuccess()
            }
        })
    }
}